package br.pucrs.lognplay.repository.mapper.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import br.pucrs.lognplay.entity.StaticView;
import br.pucrs.lognplay.repository.RepositoryException;
import br.pucrs.lognplay.repository.StaticViewRepository;

public class StaticViewMapper extends GenericMapper<StaticView, String> implements StaticViewRepository {

	public StaticViewMapper() {
		super();
	}

	public StaticViewMapper(EntityManager entityManager) {
		super(entityManager);
	}

	public List<StaticView> listByClientId(String clientId) throws RepositoryException {
		try {
			TypedQuery<StaticView> typedQuery = getEntityManager().createQuery("SELECT staticView FROM StaticView staticView WHERE staticView.client.id = :clientId", StaticView.class);
			typedQuery.setParameter("clientId", clientId);
			return typedQuery.getResultList();
		} catch (Exception e) {
			throw new RepositoryException("Error on list static views by client id", e);
		}
	}
}
